package com.touchwisdom.fetch.core.web;

import java.sql.Timestamp;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.touchwisdom.fetch.core.model.TFetchConfig;
import com.touchwisdom.modular.common.util.ClassPathRender;
import com.touchwisdom.modular.common.util.ObjectId;

/**
 * 系统配置信息类
 * 
 * @filename FetchSystemConfigController.java
 * @author ggeagle
 * @datetime 2017年9月22日 下午12:59:04
 */
public class FetchSystemConfigController extends Controller {
	public void index() {
		TFetchConfig fetchConfig = TFetchConfig.dao.getRootConfig();
		this.setAttr("item", fetchConfig);
		this.render(new ClassPathRender("/templates/fetch/config/index.html"));
	}

	public void save() {
		TFetchConfig item = this.getModel(TFetchConfig.class, StringUtils.EMPTY);
		Timestamp current = new Timestamp(System.currentTimeMillis());
		if (StrKit.notBlank(item.getId())) {
			item.setUpdateTime(current);
			item.update();
		} else {
			item.setId(new ObjectId().toHexString());
			item.setCreateTime(current);
			item.setUpdateTime(current);
			item.save();
		}
		this.redirect("index");
	}
}